package com.zgzg.shop.pay.base;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

public abstract class BaseController {

    private static final String SUCCESS = "SUCCESS";

    protected static ResponseEntity<Result> ok() {
        return ResponseEntity.ok(new Result()
                .setCode(HttpStatus.OK.value())
                .setMsg(SUCCESS));
    }

    protected static <T> ResponseEntity<Result> ok(T t) {
        return ResponseEntity.ok(new Result()
                .setCode(HttpStatus.OK.value())
                .setMsg(SUCCESS)
                .setData(t));
    }
    protected static <T> ResponseEntity<Result<T>> okG(T t) {
        return ResponseEntity.ok(new Result<T>()
                .setCode(HttpStatus.OK.value())
                .setMsg(SUCCESS)
                .setData(t));
    }

    protected static <T> ResponseEntity<Result> ok(HttpStatus httpStatus, T t) {
        return ResponseEntity.ok(new Result()
                .setCode(httpStatus.value())
                .setData(t));
    }
    protected static <T> ResponseEntity<Result<T>> okG(HttpStatus httpStatus, T t) {
        return ResponseEntity.ok(new Result()
                .setCode(httpStatus.value())
                .setData(t));
    }

    protected static <T> ResponseEntity<Result<T>> success(T t) {
        return ResponseEntity.ok(new Result()
                .setCode(HttpStatus.OK.value())
                .setMsg(SUCCESS)
                .setData(t));
    }

    protected static <T> ResponseEntity<Result<T>> success(HttpStatus httpStatus, T t) {
        return ResponseEntity.ok(new Result()
                .setCode(httpStatus.value())
                .setData(t));
    }

    protected static ResponseEntity<Result> fail() {
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Result()
                .setCode(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()));
    }

    protected static ResponseEntity fail(String msg) {
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Result()
                .setCode(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .setMsg(msg));
    }

    protected static <T> ResponseEntity<Result> fail(T data, String msg) {
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Result()
                .setCode(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .setData(data)
                .setMsg(msg));
    }

}
